package org.kcloud.webgate.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.gtiles.components.login.authentication.impl.AuthenticatedUserImpl;
import org.gtiles.components.login.service.IPostHandlerAction.IPostHandlerAction;
import org.kcloud.webgate.utils.SpringBeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.goldgov.ms.adapter.call.RemoteCallService;

/**
 * @author Tony
 */
@Service
public class ShanxuePostHandlerAction implements IPostHandlerAction {
	
	Logger log=LoggerFactory.getLogger(ShanxuePostHandlerAction.class);
	@SuppressWarnings("unchecked")
	@Override
	public void loginPostHandler(HttpServletRequest request, HttpServletResponse response) {
		String userInfo = (String) request.getSession().getAttribute("USER_JSON");
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			AuthenticatedUserImpl userBean = objectMapper.readValue(userInfo, AuthenticatedUserImpl.class);
			Map<String, String> parmMap = new HashMap<String, String>();
			parmMap.put("userID", userBean.getEntityID());
			RemoteCallService remoteCallService = SpringBeanUtils.getBean(RemoteCallService.class);
			Map<String,String> map=new HashMap<String,String>();
			map.putAll(remoteCallService.getForObject("loginPostHandler", Map.class, parmMap));
			String EXTEND_JSON = objectMapper.writeValueAsString(map);
			log.info("登录后处理扩展信息:"+EXTEND_JSON);
			request.getSession().setAttribute("EXTEND_JSON", EXTEND_JSON);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
